package control;

import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.Projeto;
import model.UsuarioCT;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import dao.ProjetoDAO;
import dao.UsuarioProjetoDAO;

public class AtualizaAction extends Action {
	
	public ActionForward execute(ActionMapping map, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws SQLException {
		
		HttpSession session = request.getSession();
		UsuarioCT usuario = (UsuarioCT)session.getAttribute("usuario");
		
		//Dados do jsp (nomeUnix)
		String nomeUnix = request.getParameter("nomeUnix");
		
		Facade facade = Facade.getInstance();
		boolean ehAdmin = facade.ehAdministrador(usuario.getUsuario(),nomeUnix);

		String action = "";
		if (ehAdmin) {
			Projeto p = facade.pesquisaProjeto(request.getParameter("nomeUnix"));
			request.setAttribute("projeto", p);
			action = "modificarProjeto";
		}
		else {
			action = "nao_modificarProjeto";
		}
		return map.findForward(action);
	}
}
